import { IMoveAlgorithm, IElmentRoot, IVector } from "../../ADCore/Interfaces/IRole";
import GameWorldConfig from "../../ADCore/Config/GameWorldConfig";
import MathMontion from "../../ADCore/Plugin/Algorithm/MathMontion";
/**根据指定圆心进行圆周率运动 */
export default class PIMove implements IMoveAlgorithm {

    getPyhicsVector(): IVector {
        return null;
    }
    vector: IVector;
    updateOptions(option: any) { 
        if(option.speed){
            this.speed=option.speed;
        }
         if(option.angle!=undefined){
            this.angle = option.angle;
        }
        this.speedRate = this.speed / GameWorldConfig.worldSpeedRate / 5;
    }
    private sprite: Laya.Sprite;
    /**当前角度 */
    angle: number;
    //元素速度
    speed: number=0.01;
    /**旋转半径 */
    private radius: number = 150;
    /**角速度 */
    private speedRate: number;
    private centerX: number;
    private centerY: number;
    /**设置参数： {angle:0,speed:20,x,y,radius:0}  x,y为中心坐标点*/
    setOptions(element: IElmentRoot, option: any) {
        this.sprite = element.spriteBase; 
        this.radius = option.radius;
        this.centerX = option.x;
        this.centerY = option.y; 
        this.updateOptions(option);
    }
    private isEnable=true;
    enable(isEnable:boolean) {
        this.isEnable=isEnable;
    }
    move() { 
        if(!this.isEnable)return;
        /**求角度x，y坐标 */
        var point = MathMontion.moveCircleByAngle(this.angle, this.radius);

        this.vector=MathMontion.moveLineByAngle(this.angle,this.speed / GameWorldConfig.worldSpeedRate);
        //绕中心坐标运行 中心坐标
        this.sprite.x = point.x + this.centerX;// GameWorldConfig.worldCenterX;
        this.sprite.y = point.y + this.centerY;// GameWorldConfig.worldCenterY;
        // this.sprite.rotation+=1;
        this.angle += this.speedRate;
    }
}